/**
 * 网络请求的入口
 * 返回promise对象
 * @author[donghui]
 * 2018-4-1
 */
// const domain = "https://weixin.rangwolai.com.cn/xcx/"//线上
const domain = "https://xcx.rangwolai.com.cn/xcx/"//测试

 /**
  * method 大写
  * headers content-type 小写
  * 返回promise对象
  */
function _request(method, url, data, headers) {
  //这里只支持浅拷贝，不支持对象嵌套复制
  console.log(wx.getStorageSync('sessionId'))
  if (!wx.getStorageSync('sessionId')) {
    var sendHeaders = Object.assign({
      "Content-Type": "application/json;charset=UTF-8",
      "Cache-Control": "no-cache"
    }, headers)
  } else {
    var sendHeaders = Object.assign({
      "Content-Type": "application/json;charset=UTF-8",
      "Cache-Control": "no-cache",
      "Cookie": 'JSESSIONID='+wx.getStorageSync('sessionId')
    }, headers)
  }
  return wx.pro.request({
    url: domain + url,
    data: data,
    method: method,
    header: sendHeaders
  })
}

function _get(url, data, headers) {
  return _request('GET', url, data, headers)
}

function _post(url, data, headers) {
  return _request('POST', url, data, headers)
}

module.exports = {
  get: _get,
  post: _post
}